from sqlmodel import SQLModel, Field
from typing import Any, Optional
import re
from pydantic import validator

from models.admin.system.Sms import EnvetEnum
class LoginParams(SQLModel):
    username: str
    password: str
class LoginResponse(SQLModel):
    id : int
    nickname : str
    group_id : int
    gender: int
    bio: str
    money: int
    score: int
    level: int
    mobile: str
    accessToken: str
    refreshToken: str
    expires: str
    
class RegisterParams(SQLModel):
    username: str
    password: str
    email: str
    mobile: str
    nickname: str
    joinip: Optional[str] = None
    jointime: Optional[int] = None

class SMSRequest(SQLModel):
    mobile: str = Field(max_length=11)
    event: EnvetEnum

    @validator('mobile')
    def validate_mobile(cls, v):
        if not re.match(r"^1[3-9]\d{9}$", v):
            raise ValueError('Invalid mobile number format')
        return v